package com.api.custom.email;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;

/**
 * @author	Huangwm
 * @date  	2020年5月11日 下午4:55:37
 * @project	E9_Project
 * @name	GetEmailSetupInfo
 * @package com.api.custom.email
 * @description	
 */
@Path("/custom/email")
public class GetEmailSetupInfo {

	public static Log log = LogFactory.getLog(GetEmailSetupInfo.class);
	@GET
	@Path("/getEmailSetupInfo")
	@Produces(MediaType.APPLICATION_JSON)
	public static JSONObject getEmailSetupInfo(@Context HttpServletRequest request,@Context HttpServletResponse response){
		JSONObject result = new JSONObject();
		String userid = "";
		HttpSession session = request.getSession();
		User user = (User) session.getAttribute("weaver_user@bean");
		User localUser = HrmUserVarify.getUser(request,response);
		userid = user.getUID()+"";
		
		String loginid = "";
		String workcode = "";
		RecordSet rs1 = new RecordSet();
		String sql1 = "select loginid,workcode,lastname from HrmResource where id="+userid;
		//log.info(sql1);
		if(rs1.execute(sql1)&&rs1.next()){
			loginid = Util.null2String(rs1.getString("loginid"));
			workcode = Util.null2String(rs1.getString("workcode"));
		}
		String emailServer = "";
		RecordSet rs2 = new RecordSet();
		String sql2 = "select defmailuser,defmailfrom from SystemSet ";
		if(rs2.execute(sql2)&&rs2.next()){
			//log.info(sql2+rs2.getString("defmailfrom"));
			emailServer = rs2.getString("defmailfrom").split("@")[1];		
		}
		
		result.put("userid", userid);
		result.put("loginid", loginid);
		result.put("workcode", workcode);
		result.put("emailServer", emailServer);
		log.info(result);
		return result;
	}
}
